package com.session; /**
 * @author wzm
 * @create 2023-05-10 16:38
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/session01")
public class SessionServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        response.setContentType("text/html;charset=utf-8");

        session.setAttribute("key1","value1");

        //超时时间 秒为单位
        session.setMaxInactiveInterval(3);
        //session.invalidate();



        response.getWriter().write("你好，我们已经存储了session数据");

    }
}
